home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2004 April / Gamestar_61_2004-04_dvdb.iso / DVDStar / Editace / hltp.exe / {app} / Applications / QuArK / plugins / mapbadtexscale.py < prev    next >
Text File  |  2004-01-05  |  8KB  |  278 lines

  1. """   QuArK  -  Quake Army Knife
  2.  
  3. Python code to find faces with bad texture scales
  4. """
  5. #
  6. # Copyright (C) 1996-99 Armin Rigo
  7. # THIS FILE IS PROTECTED BY THE GNU GENERAL PUBLIC LICENCE
  8. # FOUND IN FILE "COPYING.TXT"
  9. #
  10.  
  11. #$Header: /cvsroot/quark/runtime/plugins/mapbadtexscale.py,v 1.8 2003/12/18 21:51:46 peter-b Exp $
  12.  
  13. Info = {
  14.    "plug-in":       "Bad Texture Scale Finder",
  15.    "desc":          "Finds brush faces with bad texture scales",
  16.    "date":          "1 April 2002",
  17.    "author":        "tiglari",
  18.    "author e-mail": "tiglari@hexenworld.com",
  19.    "quark":         "Version 6.3" }
  20.  
  21.  
  22. from quarkpy.maputils import *
  23. import quarkpy.mapmenus
  24. import quarkpy.mapcommands
  25. import quarkpy.dlgclasses
  26. from quarkpy import guiutils
  27. import quarkpy.mapsearch
  28.  
  29. import mapmadsel
  30. import quarkx
  31.  
  32. #
  33. # A `Live Edit' dialog.  Note the action buttons, which
  34. #   use a rather convoluted technique to produce their
  35. #   effects (when a button is bushed,
  36. #   quarkpy.qmacro.MACRO_zapview is executed with an index
  37. #   saying which, this calls the appropriate function of the
  38. #   dialog, which was attached to the editor when executed).
  39. #
  40. # A ListBox would be better than a ComboBox for data entry,
  41. #   but FormCFG.pas doesn't at the moment support ListBoxes.
  42. #   In principle, this could be fixed.
  43. #
  44.  
  45. class BadTexScaleDlg (quarkpy.dlgclasses.LiveEditDlg):
  46.     #
  47.     # dialog layout
  48.     #
  49.  
  50.     endcolor = AQUA
  51.     size = (240,180)
  52.     dfsep = 0.40
  53.  
  54.     dlgdef = """
  55.         {
  56.         Style = "9"
  57.         Caption = "Bad Texture Scale Finder"
  58.  
  59.         micros: = {
  60.           Typ = "C"
  61.           Txt = "Bad Tex:"
  62.           Items = "%s"
  63.           Values = "%s"
  64.           Hint = "These are the faces with bad texture scales.  Pick one," $0D " then push buttons on row below for action."
  65.         }
  66.  
  67.           
  68.         sep: = { Typ="S" Txt=""}
  69.  
  70.         buttons: = {
  71.         Typ = "PM"
  72.         Num = "1"
  73.         Macro = "viewbadtex"
  74.         Caps = "I"
  75.         Txt = "Actions:"
  76.         Hint1 = "Inspect the chosen one"
  77.         }
  78.  
  79.         num: = {
  80.           Typ = "EF1"
  81.           Txt = "# found"
  82.         }
  83.  
  84.         badangle: = {
  85.           Typ = "EF001"
  86.           Txt = "smallest angle: "
  87.           Hint = "Faces whose texture axes make an angle smaller than this (degrees) are deemed bad"
  88.         }
  89.         
  90.         badtexaxis: = {
  91.           Typ = "EF001"
  92.           Txt = "smallest axis: "
  93.           Hint = "Faces with a texture axis smaller than this (units) are deemed bad"
  94.         }
  95.         
  96.         
  97.         sep: = { Typ="S" Txt=""}
  98.  
  99.         exit:py = {Txt="" }
  100.     }
  101.     """
  102.  
  103.     def inspect(self):
  104.         index = eval(self.chosen)
  105.         #
  106.         # FIXME: dumb hack, revise mapmadsel
  107.         #
  108.         m = qmenu.item("",None)
  109.         m.object=self.pack.baddies[index]
  110.         mapmadsel.ZoomToMe(m)
  111.         mapmadsel.SelectMe(m)
  112.         #
  113.         # Some grotty crap to set the mpp to the face page
  114.         #
  115.         Spec1 = qmenu.item("", quarkpy.mapmenus.set_mpp_page, "")
  116.         Spec1.page = 3 # face properties page
  117.         quarkpy.mapmenus.set_mpp_page(Spec1) 
  118.         
  119.  
  120. #
  121. # Define the viewbadtex macro here, put the definition into
  122. #  quarkpy.qmacro, which is where macros called from delphi
  123. #  live.
  124. #
  125. def macro_viewbadtex(self, index=0):
  126.     editor = mapeditor()
  127.     if editor is None: return
  128.     if index==1:
  129.         editor.badtexscaledlg.inspect()
  130.         
  131. quarkpy.qmacro.MACRO_viewbadtex = macro_viewbadtex
  132.  
  133. #
  134. # For a face, for each other different face, the vertex furthest
  135. #  away from the other face must be far enough away/
  136. #
  137. def texIsBad(face, badsize, badangle):
  138.     (p0, p1, p2) = face.threepoints(2)
  139.     u = (p1-p0)
  140.     v = (p2-p0)
  141. #    debug("%s - %.2d:%.2f"%(face.name,badsize,badangle))
  142.     if abs(u)<badsize or abs(v)<badsize:
  143.         return 1
  144. #    debug('yo dude')
  145.     cos = u.normalized*v.normalized
  146.     angle = math.fabs(math.acos(u.normalized*v.normalized))/deg2rad
  147. #    debug("%s: %.6f"%(face.name, angle))
  148.     return angle<badangle
  149.                     
  150.            
  151. def getBad(badsize, badangle, editor):
  152.     baddies = []
  153.     for face in editor.Root.findallsubitems("",":f"):
  154.         if texIsBad(face,badsize, badangle):
  155.             baddies.append(face)
  156.     return baddies
  157.     
  158. def badClick(m):
  159.     editor=mapeditor()
  160.  
  161.     badangle = guiutils.getSetupOption("badangle","5")
  162.     badtexaxis = guiutils.getSetupOption("badtexaxis", "1")
  163.     
  164.     baddies = getBad(eval(badtexaxis), eval(badangle), editor)
  165.     
  166.     
  167.     #
  168.     # Here we start the Live Edit dialog invocation sequence.
  169.     #  Data to be tracked during the life of the dialog goes
  170.     #  here.
  171.     #
  172.     class pack:
  173.         "stick stuff in this"
  174.     pack.baddies=baddies
  175.     pack.badangle=badangle
  176.     pack.badtexaxis=badtexaxis
  177.     pack.seen = 0
  178.       
  179.     #
  180.     # This loads the relevant data into the dialog, gets
  181.     #  recalled after changes.
  182.     #
  183.     def setup(self, pack=pack, editor=editor):
  184.         self.pack=pack
  185.         #
  186.         # Part of the convolution for the buttons, to communicate
  187.         #  which objects methods should be called when one pushed.
  188.         # Cleaned up in onclosing below.
  189.         #
  190.         editor.badtexscaledlg=self
  191.         
  192.         #
  193.         # Names and list-indexes of thin brushes
  194.         #
  195.         ran = range(len(pack.baddies))
  196.         pack.slist = map(lambda obj,num:"%d) %s:%s"%(num+1,obj.parent.shortname,obj.shortname), pack.baddies, ran)
  197.         pack.klist = map(lambda d:`d`, ran)
  198.  
  199.         self.src["micros$Items"] = pack.slist.join("\015")
  200.         self.src["micros$Values"] = pack.klist.join("\015")
  201.         if not pack.seen and len(ran)>0:
  202.             self.src["micros"] = '0'
  203.             self.chosen = '0'
  204.             pack.seen = '0'
  205.         elif len(ran)==0:
  206.             self.chosen = ''
  207.             pack.seen = ''
  208.             
  209.         #
  210.         # Note the commas, EF..1 controls take 1-tuples as data
  211.         #
  212.         self.src["num"]=len(pack.klist),
  213.         self.src["badangle"]=eval(pack.badangle),
  214.         self.src["badtexaxis"]=eval(pack.badtexaxis),
  215.  
  216.         
  217.  
  218.     #
  219.     # When data is entered, this gets executed.
  220.     #
  221.     def action(self, pack=pack, editor=editor):
  222.         src = self.src
  223.         #
  224.         # note what's been chosen
  225.         #
  226.         self.chosen = src["micros"]
  227.         #
  228.         # see if thinness threshold has been changed
  229.         #
  230.         anglechange, newangle = guiutils.dlgNumberCheck(self, pack, "badangle", 5.00)
  231.         axischange, newaxis = guiutils.dlgNumberCheck(self, pack, "badtexaxis", 1.00)
  232.         if anglechange or axischange:
  233.             pack.baddies = getBad(newaxis, newangle, editor)
  234.             
  235.     #
  236.     # Cleanup when dialog closes (not needed if no mess has
  237.     #  been created)
  238.     #
  239.     def onclosing(self,editor=editor):
  240.         del editor.badtexscaledlg
  241.         
  242.     #
  243.     # And here's the invocation. 2nd arg is a label for storing
  244.     #  position info in setup.qrk.
  245.     #
  246.     BadTexScaleDlg(quarkx.clickform, 'badtexscale', editor, setup, action, onclosing)
  247.  
  248.  
  249. quarkpy.mapsearch.items.append(qmenu.item('Find Bad Tex Scale', badClick,
  250.  "|Find Bad Tex Scale:\n\nThis finds faces whose texture axes are almost parallel.|intro.mapeditor.menu.html#searchmenu"))
  251.  
  252. #$Log: mapbadtexscale.py,v $
  253. #Revision 1.8  2003/12/18 21:51:46  peter-b
  254. #Removed reliance on external string library from Python scripts (second try ;-)
  255. #
  256. #Revision 1.7  2003/03/21 05:47:45  cdunde
  257. #Update infobase and add links
  258. #
  259. #Revision 1.6  2002/05/21 10:24:12  tiglari
  260. #make collected item numbering start with 1)
  261. #
  262. #Revision 1.5  2002/05/21 09:16:16  tiglari
  263. #fix problems with selection dialog: the first of two with identical names was
  264. # always being chosen, and first item on list wouldn't load
  265. #
  266. #Revision 1.4  2002/05/12 08:00:15  tiglari
  267. #minor corrections
  268. #
  269. #Revision 1.3  2002/04/30 22:55:33  tiglari
  270. #add import quarkpy.mapsearch  statement
  271. #
  272. #Revision 1.2  2002/04/27 23:00:13  tiglari
  273. #add import statement
  274. #
  275. #Revision 1.1  2002/04/01 08:31:48  tiglari
  276. #modelled on mapmicrobrush.py, but some stuff abstracted into quarkpy.guiutils
  277. #
  278.